package com.future.controller;

import java.util.Date;

import javax.validation.constraints.NotNull;

import com.future.common.annotation.ControllerMapping;
import com.future.common.base.BaseController;
import com.future.dao.WeekFoodDao;
import com.future.model.Weekfood;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.tx.Tx;

@ControllerMapping("/weekfood")
public class WeekFoodController extends BaseController {
	@Inject
	private WeekFoodDao weekFoodDao;

	@Before(Tx.class)
	public void addWeekFood(@NotNull(message = "添加时间不能为空") Date addDate, @NotNull(message = "图片不能为空") String sptp) {
		Weekfood weekfood = new Weekfood();
		weekfood.setAdddate(addDate);
		weekfood.setSptp(sptp);
		this.weekFoodDao.save(weekfood);
		renderSuccess();
	}

	@Before(Tx.class)
	public void deleteWeekFood(@NotNull(message = "请选择删除对象") Long spid) {
		this.weekFoodDao.deleteById(spid);
		renderSuccess();
	}

	public void findWeekFood() {
		renderResult("weekfood", this.weekFoodDao.getWeekFood());
	}
}
